<?php
include 'db.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $id = $_POST['id'];
    $name = $_POST['name'];
    $description = $_POST['description'];
    $price = $_POST['price'];
    $status = $_POST['status'];
    $log_enabled = $_POST['log_enabled'];

    $stmt = $pdo->prepare("UPDATE tools SET name = ?, description = ?, price = ?, status = ?, log_enabled = ? WHERE id = ?");
    $stmt->execute([$name, $description, $price, $status, $log_enabled, $id]);

    if ($stmt->rowCount() > 0) {
        echo json_encode(['success' => true, 'message' => '小工具编辑成功']);
    } else {
        echo json_encode(['success' => false, 'message' => '小工具编辑失败']);
    }
} else {
    echo json_encode(['success' => false, 'message' => 'Invalid request method']);
}